import db from "../util/db";
export default {
	createTalbe() {
		return db.executeSql(`
		create table if not exists money(
		id integer  not null primary key,
		parent_Id not null,
		type_name not null,
		money real not null,
		status text
		)
		`);
	},
	countAllMoney() {
		return db.selectSql(`
		select sum(money) as allMoney from money
		`);
	},
	countMoneyAndGroupByType() {
		return db.selectSql(`
		select type_name ,sum(money) from money group by type_name
		`);
	},
	countMoneyByParentId(parentId) {
		return db.selectSql(`
		select sum(money) from money where parent_Id = '`+parentId+`'
		`);
	},
	selectAllData() {
		return db.selectSql(`
				select  * from money
				`);
	},
	selectDataById(id){
		return db.selectSql(`
				select  * from money where id = '`+id+`'
				`);
	},
	selectDateByParentId(parentId){
		return db.selectSql(`
				select  * from money where parent_Id = '`+parentId+`'
				`);
	},
	updatedata(id,money) {
		return db.executeSql(`
			update money set money = '` + money + `' where id = '`+id+`'
		`);
	},
	insertdata(parentId, typeName, money, status) {
		return db.executeSql(`
			insert into money(parent_Id,type_name,money,status) VALUES('` + parentId + `','` + typeName + `','` + money + `','1')
		`);
	},
	deleteDateById(id) {
		return db.executeSql(`
			delete from money where id = '`+id+`'
		`);
	},
	deleteAllDate() {
		return db.executeSql(`
			delete from money
		`);
	}
}